#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>

using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

int widthOfBinaryTree(TreeNode* root) {
    vector<pair<TreeNode*, unsigned int>> q;
    unsigned int ret = 0;

    q.emplace_back(root, 1);

    while (q.size())
    {
        auto& [x1, y1] = q[0];
        auto& [x2, y2] = q.back();
        ret = max(ret, y2 - y1 + 1);

        vector<pair<TreeNode*, unsigned int>> tmp;
        for (auto& [x, y] : q)
        {
            if (x->left != nullptr)
                tmp.emplace_back(x->left, 2 * y);
            if (x->right != nullptr)
                tmp.emplace_back(x->right, 2 * y + 1);
        }

        q = tmp;
    }

    return ret;
}

int main()
{

	return 0;
}